import request from "@/utils/request";

const STRATEGY_BASE_URL = "/ig/indicator";

const indicatorAPI = {
  List(queryParams?: IndicatorListParameter) {
    return request<any, IndicatorListResponse[]>({
      url: `${STRATEGY_BASE_URL}/list`,
      method: "get",
      params: queryParams,
    });
  },
  Delete(data?: IdListParameter) {
    return request({
      url: `${STRATEGY_BASE_URL}/delete`,
      method: "post",
      data: data,
    });
  },
  Operational(data?: IndicatorListParameter) {
    return request<any, IndicatorOperationalResponse>({
      url: `${STRATEGY_BASE_URL}/operational`,
      method: "post",
      data: data,
    });
  },
  TestRun(data?: IndicatorListParameter) {
    return request<any, IndicatorOperationalResponse>({
      url: `${STRATEGY_BASE_URL}/operational/test`,
      method: "post",
      data: data,
    });
  },
  Topology(data?: IndicatorListParameter) {
    return request<any, any>({
      url: `${STRATEGY_BASE_URL}/topology`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取指标详情
   */
  Info(data?: IndicatorListParameter) {
    return request<any, IndicatorInfoResponse>({
      url: `${STRATEGY_BASE_URL}/info`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取指标SQL
   */
  Sql(data?: IndicatorListParameter) {
    return request<any, ExmaineSqlResponse>({
      url: `${STRATEGY_BASE_URL}/check/sql`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取指标详情--包含异常规则
   */
  IndicatorEditInfo(data?: IndicatorListParameter) {
    return request<any, IndicatorAbnormalInfoResponse>({
      url: `${STRATEGY_BASE_URL}/info/abnormal`,
      method: "post",
      data: data,
    });
  },
  /**
   * 获取指标异常规则列表
   */
  AbnormalRules() {
    return request<any, AbnormalRuleResponse[]>({
      url: `${STRATEGY_BASE_URL}/abnormal/list`,
      method: "post",
    });
  },
  /**
   * 更新指标异常规则
   */
  UpdateByIdForAbnormal(data?: UpdateByIdForAbnormalParameter) {
    return request<any, any>({
      url: `${STRATEGY_BASE_URL}/update`,
      method: "post",
      data: data,
    });
  },
};

export default indicatorAPI;

export interface IndicatorListParameter {
  id?: number;
}

export interface IndicatorListResponse {
  id?: number;
  indicatorName?: string;
  domainId?: number;
  alias?: string;
  description?: string;
  tag?: string;
  department?: string;
  subjectId?: number;
  groupId?: number;
  aggregationMethod?: string;
  dataType?: string;
  length?: string;
  accuracy?: string;
  tableId?: number;
  creator?: string;
  createTime?: string;
  updateTime?: string;
}

export interface IdListParameter {
  ids?: number[];
}

export interface IndicatorOperationalResponse {
  fileNames?: string[];
  entityList?: any[];
}

export interface IndicatorTopologyResponse {
  id?: number;
  name?: string;
  children?: IndicatorTopologyResponse[];
}

export interface IndicatorInfoResponse {
  id?: number;
  indicatorName?: string;
  dataSourceName?: string;
  domainName?: string;
  alias?: string;
  description?: string;
  tag?: string;
  department?: string;
  subjectId?: number;
  groupName?: string;
  aggregationMethod?: string;
  dataType?: string;
  size?: string;
  digit?: string;
  tableName?: string;
  creator?: string;
  createTime?: string;
  updateTime?: string;
}

export interface ExmaineSqlResponse {
  /** sql语句 */
  sql?: string;
}

export interface AbnormalRuleResponse {
  id?: number;
  name?: string;
}

/** 指标详情--包含异常规则 */
export interface IndicatorAbnormalInfoResponse {
  // 主键
  id?: number;
  // 指标名称
  indicatorName?: string;
  // 数据源名称
  dataSourceName?: string;
  // 指标域名称
  domainName?: string;
  // 别名
  alias?: string;
  // 标签
  tag?: string;
  // 部门名称
  department?: string;
  // 主题id
  subjectId?: number;
  // 指标分组
  groupName?: string;
  // 聚合方法
  aggregationMethod?: string;
  // 数据类型
  dataType?: string;
  // 长度
  size?: string;
  // 精度
  digit?: string;
  // 指标表名称
  tableName?: string;
  // 数据期列
  timeColumn?: string;
  // 维度列
  dimesionColumn?: string;
  // 维度列值
  dimesionValue?: string;
  // 异常规则id
  abnormalId?: number;
}

export interface UpdateByIdForAbnormalParameter {
  // 主键
  id?: number;
  // 指标名称
  indicatorName?: string;
  // 异常规则id
  abnormalId?: number;
}
